const processData = (error) => {
  const data = {
    message: error.message,
    name: error.name,
  };
  const stack = error.stack;
  const matchUrl = stack.match(/http:\/\/[^\n]*/)[0];
  console.log(matchUrl);
  data.fileName = matchUrl.match(/http:\/\/(?:\S*)\.js/)[0];
  const [, row, column] = matchUrl.match(/:(\d+):(\d+)/);
  data.row = row;
  data.column = column;//上线代码会压缩 source-map 映射 找到真实的报错
  return data;
};

export default {
  init(cb) {
    //无法监听图片错误
    // window.addEventListener('error',fn,true);  //捕获阶段
    // promise 错误无法捕获 windiw.addEventListener('unhandledrejection',fn);
    window.onerror = function (message, source, lineno, colno, error) {
      console.dir(error);
      const data = processData(error);
      cb(data);
    };
  },
};
